package pl.edu.utp.kursy;

import java.awt.BorderLayout;
import pl.edu.utp.kursy.database.Accomodation;

public class AccomodationWindow extends JFrameGUI {
    
    private AccomodationInfoPanel accomodationInfoPanel;
    private AccomodationWindowApproveListener listener;

    public AccomodationWindow() {
        initComponents();
        
        accomodationInfoPanel = new AccomodationInfoPanel(null);
        accomodationInfoPanel.setEditableMode(true);
        accomodationFieldsPanel.add(accomodationInfoPanel, BorderLayout.CENTER);
        setCenteredPosition();
    }
    
    public void setAccomodationWindowApproveListener(AccomodationWindowApproveListener listener){
        this.listener = listener;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        accomodationFieldsPanel = new javax.swing.JPanel();
        cancelButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(getString("accomodation_place"));

        accomodationFieldsPanel.setLayout(new java.awt.BorderLayout());

        cancelButton.setText(getString("cancel"));
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        addButton.setText(getString("accomodation_add"));
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 315, Short.MAX_VALUE)
                .addComponent(addButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(accomodationFieldsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(accomodationFieldsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(addButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        Accomodation accomodation = accomodationInfoPanel.getAccomodation();
        if(listener != null){
            listener.onAccomodationWindowApprove(accomodation);
        }
        dispose();
        
    }//GEN-LAST:event_addButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel accomodationFieldsPanel;
    private javax.swing.JButton addButton;
    private javax.swing.JButton cancelButton;
    // End of variables declaration//GEN-END:variables

    
    
    public interface AccomodationWindowApproveListener{
        public void onAccomodationWindowApprove(Accomodation accomodation);
    }
}
